/**
 * Configure your Gatsby site with this file.
 *
 * See: https://www.gatsbyjs.com/docs/gatsby-config/
 */
const path = require('path');

require('dotenv').config({
  path: `.env.${process.env.NODE_ENV}`,
});

const strapiConfig = {
  apiURL: process.env.STRAPI_API_URL,
  accessToken: process.env.STRAPI_TOKEN,
  collectionTypes: ['post'],
  // singleTypes: [],
};

module.exports = {
  /* Your site config here */
  siteMetadata: {
    title: 'Gatsby',
    description: 'Gatsby: 基于 React 的静态站点生成器',
    author: 'Duyb',
  },
  plugins: [
    // 将本地 JSON 文件数据添加到数据层中
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `json`,
        path: path.resolve(__dirname, 'json'),
      },
    },

    // 将本地 XML 文件数据添加到数据层中
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `xml`,
        path: path.resolve(__dirname, 'xml'),
      },
    },

    // 将本地 markdown 文件作为数据源构建文章列表
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `markdown`,
        path: path.resolve(__dirname, 'src/posts/'),
      },
    },
    {
      resolve: 'gatsby-transformer-remark',
      options: {
        plugins: [
          // processes images in markdown
          'gatsby-remark-images',
        ],
      },
    },

    // 图像优化
    'gatsby-transformer-json',
    'gatsby-plugin-image',
    'gatsby-plugin-sharp',
    'gatsby-transformer-sharp', // Needed for dynamic images

    // Strapi config
    // {
    //   resolve: 'gatsby-source-strapi',
    //   options: strapiConfig,
    // },

    // ! 自定义插件 gatsby-source-mystrapi
    {
      resolve: 'gatsby-source-mystrapi',
      options: strapiConfig,
    },

    // ! 自定义插件 将 xml 转化为 js 对象
    'gatsby-transformer-xml',

    // SEO 优化
    'gatsby-plugin-react-helmet',

    // 支持 Less
    'gatsby-plugin-less',
  ],
};
